package jpg1980.gttunes.dao;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.log4j.Logger;

public abstract class AbstractDao
{
	static Logger logger = Logger.getLogger(AbstractDao.class);
	private Connection connection;
	
	public AbstractDao()
	{
		try
		{
			connection = DataSourceServiceLocator.INSTANCE.getDataSource().getConnection();
		}
		catch (SQLException e)
		{
			throw new RuntimeException("Error getting connection from datasource", e);
		}
	}
	
	public Connection getConnection()
	{
		return connection;
	}
	
	// Closes the database connection
	public void cleanUp()
	{
		try
		{
			logger.debug("Closing db connection");
			connection.close();
		}
		catch (SQLException e)
		{
			logger.error(e.getMessage());
		}
	}
}
